package com.winning.devops.batch.reader.ch01;

import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

import java.util.Iterator;
import java.util.List;

/**
 * 数据读取
 *
 * @author chensj
 * @date 2020-02-29 20:20
 */
public class DemoItemReader implements ItemReader<String> {

    private final Iterator<String> iterator;

    public DemoItemReader(List<String> list) {
        this.iterator = list.iterator();
    }

    @Override
    public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
        // 数据一个一个读取
        if (iterator.hasNext()) {
            return iterator.next();
        } else {
            return null;
        }
    }
}
